package HDAPI.examples;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import HDAPI.HDBase;
import HDAPI.Settings;

public class DetectExample1 extends HttpServlet 
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
    	Utility.initHDAPISettings(this.getServletContext());
        response.setContentType("text/html");
        
        PrintWriter out = response.getWriter();

		HDBase hd = new HDBase();
        
		
		if ("NokiaN95".equals(request.getParameter("mobile"))) {
			hd.setDetectVar("user-agent", "Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95/12.0.013; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413");
		} else {
			hd.detectInit(Utility.getRequestHeaders(request), request.getRemoteAddr(), request.getRequestURL().toString());
		}
		if(hd.detectAll()){
			//redirect to a mobile version
			out.println("Mobile request detected.<br>");
		}else{
			//do nothing or regular version
			out.println("Normal request detected<br>");
		}
		
		out.println(hd.getDetect().toString());
		
		Utility.dumpError(hd, out);

    }
}